﻿using HROReporting.Controllers.ViewModels.Reservering;
using HROReporting.Infrastructure.Authentication;
using HROReporting.Infrastructure.CookieStorage;
using HROReporting.Model.Lesuren;
using HROReporting.Services.Interfaces;
using HROReporting.Services.Messaging.SchoolLocatieService;
using HROReporting.Services.Messaging.StudentService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace HROReporting.Controllers.Controllers
{
    public class ReserveringController : BaseController
    {
        private readonly IFormsAuthentication _formsAuthentication;
        private readonly IStudentService _studentService ;
        private readonly ISchoolLocatieService _schoolLocatieService;
        private readonly ILesuurService _lesuurService;

        public ReserveringController(ICookieStorageService cookieStorageService,
                                        IFormsAuthentication formsAuthentication,
                                        IStudentService studentSerivice,
                                        ISchoolLocatieService schoolLocatieService,
                                        ILesuurService lesuurService)
            : base (cookieStorageService)
        {
            _formsAuthentication = formsAuthentication;
            _studentService = studentSerivice;
            _schoolLocatieService = schoolLocatieService;
            _lesuurService = lesuurService;
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Create()
        {
            ReserveringCreateView reserveringView = new ReserveringCreateView();

            GetVergaderRuimteByRequest request = new GetVergaderRuimteByRequest();


            GetVergaderRuimteByResponse response = _schoolLocatieService.GetVergaderRuimteBy(request);


            //reserveringView.VergaderRuimte = response.VergaderRuimte;
            //reserveringView.VergaderRuimteId = response.VergaderRuimte;

            IEnumerable<Lesuur> lesuren = _lesuurService.FindAll();

            reserveringView.LesStartUren = lesuren;
            reserveringView.LesEindUren = lesuren;

            return View(reserveringView);
        }
        
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(ReserveringCreateView reserveringView, string locatie, string code)
        {
            GetVergaderRuimteByRequest request = new GetVergaderRuimteByRequest();
            request.SchoolLocatie = locatie;
            request.VergaderRuimteCode = code;

            GetStudentRequest studentRequest = new GetStudentRequest();
            studentRequest.StudentIdentityToken = _formsAuthentication.GetAuthenticationToken();
            //GetStudentResponse studentResponse = _studentService.GetStudentByAuthenticationToken(studentRequest);

            GetVergaderRuimteByRequest vergaderRuimteRequest = new GetVergaderRuimteByRequest();
            vergaderRuimteRequest.VergaderRuimteCode = reserveringView.SelectedVergaderRuimte;
            GetVergaderRuimteByResponse vergaderRuimteReponse = _schoolLocatieService.GetVergaderRuimteBy(vergaderRuimteRequest);

            Lesuur lesuurStart = _lesuurService.FindBy(Convert.ToInt16(reserveringView.SelectedLesuurStart));
            Lesuur lesuurEind = _lesuurService.FindBy(Convert.ToInt16(reserveringView.SelectedLesuurEind));

            CreateReserveringRequest createReserveringRequest = new CreateReserveringRequest();
            //createReserveringRequest.User = studentResponse.StudentId;
            //createReserveringRequest.VergaderRuimte = vergaderRuimteReponse.VergaderRuimte;
            createReserveringRequest.LesuurStart = lesuurStart;
            createReserveringRequest.LesuurEind = lesuurEind;
            createReserveringRequest.Datum = DateTime.Now;

            //_studentService.CreateReservering(createReserveringRequest);

            return View();
        }
        

        public ActionResult Details(int id)
        {
            ReserveringDetailView detailView = new ReserveringDetailView();

            //detailView.Reservering = _studentService.GetReserveringenById(id);

            return View(detailView);
        }
         
    }
}
